<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/image/favicon.ico">
    <title>大地时贷</title>
    <!-- Bootstrap core CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/navbar.css" rel="stylesheet">
    <link href="/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
    <link href="/css/registry.css" rel="stylesheet">
</head>
<body>

<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>

            </button>
            <a class="navbar-brand" href="/index">
                <img src="/image/logo.png" height="30px" width="150px">
            </a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <li class="active">
                    <img src="/image/slogan.png" height="46px" width="155px">
                </li>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</nav>
<div class="container" >
    <div class="row" >
        <div class="col-md-8" >
            <div class="form-left">
                <img src="/image/banner.jpg" >
            </div>
        </div>
        <div class="col-md-4 " >
            <div class="form-box">
                <div class="form-title">
                    <span class="title">18~60周岁均可申请</span>
                </div>
                <div class="form-name clear">
                    <input class="input-text fz-16" type="text" value="" placeholder="请输入您的姓名" id="customerName" name="name" maxlength="20"/>
                </div>
                <div class="form-phone clear">
                    <input class="input-text fz-16" type="text" value="" placeholder="请输入您的手机号码" id="phone" name="mobile" maxlength="11"/>
                </div>
                <div class="form-yzm clear" id="judgCode" style="display:none;">
                    <input class="input-text fz-16" type="text" value="" placeholder="请输入验证码" id="yzmnum" name="mobile" maxlength="6" />
                    <span class="yzm_btn yzm_btn_orange" id="yzm_btn">发送验证码</span>
                </div>
                <div class="form-btn ">
                    <a href="javascript:void(0);" onclick="acc()" id="btnNext0">立即申请</a>
                </div>
            </div>
        </div>

    </div>


</div><!-- /container -->
<div class="container" >
    <footer class="footer">

        <p>客户经理电话：131 2213 1880 (付)&copy; 2018 Fly36.</p>
    </footer>

</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script type="text/javascript">
    function acc(){
        if(!isName($.trim($("#customerName").val()))){
            return false;
        }
        if(!isPoneAvailable($.trim($("#phone").val()))){
            return false;
        }
        $.ajax({
                type:'POST',
                url:'/json/add',
                contentType: 'application/json;charset=utf-8',
                data: JSON.stringify(GetJsonData()),
                dataType:'json',
                success:function (data) {

                    window.location.href="/cont/regdetail/"+data;
                },

                error:function () {
                    alert("提交失败！");
                }
            }

        )

    }
    function GetJsonData() {
        var name = $.trim($("#customerName").val()); //姓名
        var phone= $.trim($("#phone").val()); //手机号
        var json = {
            "customerName": name,
            "phone":phone
        };
        return json;
    }
    
    function isPoneAvailable(phone) {
        if (!phone) { // 手机号码
            alert('请输入手机号码');
            return false;
        } else if (!phone.match(/^1(3|4|5|7|8)\d{9}$/)) {
            alert('请正确填写手机号码');
            return false;
        } else {
            var repeat = 0,
                seque = 0;
            for (var i = 1; i < phone.length; i++) {
                if (phone.charAt(i) == phone.charAt(i - 1)) {
                    repeat++;
                    if (repeat >= 5) {
                        alert('请正确填写手机号码');
                        return false;
                    }
                } else {
                    repeat = 1;
                }
                if (phone.charAt(i) - phone.charAt(i - 1) == '1') {
                    seque++;
                    if (seque >= 6) {
                        alert('请正确填写手机号码');
                        return false;
                    }
                } else {
                    seque = 1;
                }
            }
        }
        return true;
    }

    function isName(name) {
        if (!name) { // 姓名校验
            alert('请输入姓名');
            return false;
        } else if (!name.match(/^[\u4e00-\u9fa5]{2,8}$/g)) {
            alert('姓名为2-8个汉字');
            return false;
        }
        return true;
    }
</script>
</body>
</html>